# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Kr1ss $(echo \<kr1ss+x-yandex+com\>|sed s/\+/./g\;s/\-/@/)
# Contributor: Alexander Görtz <aur@nyloc.de>
# Contributor: Dan Beste <dan.ray.beste@gmail.com>
# Contributor: Julien Nicoulaud <julien dot nicoulaud at gmail dot com>
# Contributor: stef204 <https://aur.archlinux.org/account/stef204>

pkgname=borgmatic
pkgver=1.7.12
pkgrel=2
pkgdesc='Simple, configuration-driven backup software for servers and workstations'
arch=('any')
url=https://torsion.org/borgmatic
license=('GPL3')
depends=('borg' 'python-colorama' 'python-jsonschema' 'python-requests'
         'python-ruamel-yaml' 'python-setuptools')
makedepends=('python-build' 'python-installer' 'python-wheel')
checkdepends=('python-flexmock' 'python-pytest')
optdepends=('python-llfuse: for mount action')
source=("https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz"
        'borgmatic-import_flexmock_function.patch')
sha256sums=('f0557760d42c654ffc9851f8e078b6ed0c0cae93fbd6d39080880b38f4e6401c'
            'bd1ea42be5c23b9eb0c6d6be36e4cb9983556956d9097884f259a963779c141c')
b2sums=('eb06d88320f2c49721938c756d637b6ce463192260ac734303079095c693cadde68805356249fdad86738bed8ea0afa2e7a5c5de3c68bbedba2162e1cb445cdd'
        '9b8f57ce78124e4425352c84334e704442249ce894666f34b4684b6193cf45b20c34dae6482a3f99349973f1330f8ac3df97b4abd2024ca3885c41be72c3fdf9')

prepare() {
  cd $pkgname-$pkgver
  sed -i 's,root/.local,usr,' sample/systemd/$pkgname.service
  patch --forward --strip=1 --input=../borgmatic-import_flexmock_function.patch
}

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd $pkgname-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python -m pytest -c /dev/null \
    --ignore=tests/end-to-end
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 -t "$pkgdir"/usr/lib/systemd/system sample/systemd/*
  install -d "$pkgdir"/usr/share/bash-completion/completions
  ./test-env/bin/borgmatic --bash-completion > \
    "$pkgdir"/usr/share/bash-completion/completions/$pkgname
}
